package com.parking.status.sync.netty.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {

//    @Autowired
//    @Qualifier("serverChannelInboundHandler")
//    private ChannelInboundHandlerAdapter serverChannelInboundHandler;

    @Autowired
    private RequestFinalDecoder requestFinalDecoder;

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();

        pipeline.addLast("DealHead", new RequestHeadDecoder());
        pipeline.addLast("BytesToString", new RequestUrlStringDecoder());
        pipeline.addLast("JasonToRequest", new RequestBodyDecoder());
        pipeline.addLast("RequestFinal", requestFinalDecoder);

        pipeline.addLast("ResponseFinal", new ResponseFinalEncoder());
        pipeline.addLast("StringToBytes", new ResponseUrlStringEncoder());
        pipeline.addLast("ResponseToJason", new ResponseBodyEncoder());
        pipeline.addLast("ResponseInitial", new ResponseInitialEncoder());

    }
}